<?php

(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/

get_config_keytable("bbsclass_");
empty($do) && $do = 'list';

$message = array(
	1 => '成功更新分类设置。',
	2 => '成功删除分类设置。',
);

if ($do == 'list') {
	$result = array();
	$sql = "SELECT * FROM ".DB_TABLEPRE."bbsclass  ORDER BY id asc";
	$query = $db->query($sql);
	while ($row = $db->fetch_array($query)) {
		$result[] = $row;
	}
	include_once('template/bbsclass.php');

} elseif ($do == 'update') {
	$bbsclass = array();
	$bbsclass['name'] = check_str(getGP('newname','P'));
	$bbsclass['classadmin'] = check_str(getGP('newclassadmin','P'));
	$bbsclass['type'] = check_str(getGP('newtype','P'));
	$bbsclass['uid'] = $_USER->id;
	$bbsclass['date'] = get_date('Y-m-d H:i:s',PHP_TIME);
	if (!empty($bbsclass['name'])) {
		insert_db('bbsclass', $bbsclass);
	}
	$name = getGP('name','P','array');
	$classadmin = getGP('classadmin','P','array');
	$type = getGP('type','P','array');
	foreach ($name as $key => $val) {
		$key = (int)$key;
		$db->query("UPDATE ".DB_TABLEPRE."bbsclass SET name = '$val',classadmin='$classadmin[$key]',type='$type[$key]' WHERE id = '$key'");
	}
	goto_page('admin.php?ac=bbsclass&fileurl=bbs&message=1');

} elseif ($do == 'delete') {
	$id = getGP('id','G','int');
	$db->query("DELETE FROM ".DB_TABLEPRE."bbsclass WHERE id = '$id'");
	$db->query("DELETE FROM ".DB_TABLEPRE."bbs WHERE bbsclass = '$id'");
	goto_page('admin.php?ac=bbsclass&fileurl=bbs&message=2');
}

?>